package report;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

/**
 *
 * @author freest, Oleh
 */
public abstract class ReportData {

    private Date creationDate;
    protected ArrayList headers;
    private ArrayList data;
    protected String title;

    public ReportData(ArrayList data) {
        creationDate = new Date(System.currentTimeMillis());
        headers = new ArrayList();
        this.data = new ArrayList();
        setTitle();
        setHeaders();
        loadData(data);
    }

    /**
     * Set title of report
     */
    public abstract void setTitle();

    /**
     * Set name of columns
     */
    public abstract void setHeaders();

    /**
     * Parse input data to list
     *
     * @param item
     * @return
     */
    public abstract ArrayList parseDataItem(Object item);

    private void loadData(ArrayList data) {
        Iterator dataIterator = data.iterator();
        while (dataIterator.hasNext()) {
            ArrayList item = parseDataItem(dataIterator.next());
            if (item != null) {
                this.data.add(item);
            }
        }
    }

    public ArrayList getData() {
        return data;
    }

    public String getTitle() {
        return title;
    }

    public ArrayList getHeaders() {
        return headers;
    }

    public Date getDate() {
        return creationDate;
    }
}
